package org.example.spring05.config;

import org.example.spring05.entity.Person;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/*
    ioc 容器生命周期的拦截器
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        if (bean instanceof Person && beanName.equals("p")) {
            System.out.println(bean);
            System.out.println("初始化之前的拦截器");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {

        if (bean instanceof Person && beanName.equals("p")) {

            System.out.println("初始化之后的拦截器");
            Person p = (Person) bean;
            p.setName("欧阳锋");
            return  p ;
        }
        return bean;
    }
}
